package com.larry.spark.wc

import org.apache.spark.{SparkConf, SparkContext}

object Spark03_WordCount {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark

    val conf = new SparkConf().setMaster("local").setAppName("WordCount")
    val sc = new SparkContext(conf)

    val lines = sc.textFile("C:\\Users\\larry\\IdeaProjects\\scala\\spark\\src\\main\\resources\\word.txt")

    //分词  (hello,1)
    //    (hello,1)
    //    (world,1)
    //    (world,1)
    //    (scala,1)
    val words = lines.flatMap(_.split(" ")).map((_,1))
    //    words.foreach(println)

    //统计
    val wordcount = words.reduceByKey(_+_)

    wordcount.collect().foreach(println)

    sc.stop()
  }


}
